/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlinganhang.model;

import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import quanlinganhang.bus.AccountBUS;
import quanlinganhang.dao.DrawMoneyDAO;

/**
 *
 * @author phamduong
 */
public class DrawMoneyTableModel extends AbstractTableModel {

    private String[] columnNames = {"Mã giao dịch", "Ngày rút", "Người rút",
        "Số tiền", "Ghi chú"};
    private ArrayList data;

    /**
     *
     *
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public DrawMoneyTableModel(String account) throws SQLException, ClassNotFoundException {
        this.data = DrawMoneyDAO.getDrawMoney(account);
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (!data.isEmpty()) {
            return ((ArrayList) data.get(rowIndex)).get(columnIndex);
        }
        return null;
    }

    /*
     * JTable uses this method to determine the default renderer/
     * editor for each cell.  If we didn't implement this method,
     * then the last column would contain text ("true"/"false"),
     * rather than a check box.
     */
    @Override
    public Class getColumnClass(int c) {
        if (getValueAt(0, c) == null) {
            return String.class;
        }
        return getValueAt(0, c).getClass();
    }

    /*
     * Không cho trực tiếp edit trên table
     */
    @Override
    public boolean isCellEditable(int row, int col) {
        return false;
    }
}
